﻿function loadMails(user){
    var function_url = "Index.aspx/loadEmails";
    var parametros = {
        username: user
    };
    var paramString = JSON.stringify(parametros);
    $.ajax({
        url: function_url,
        async: false,
        data: paramString,
        dataType: 'json',
        type: 'POST',
        contentType: 'application/json; charset=utf-8',
        success: function (data) {
            result = data.d;
            json_source = data.d;
            
            var table = $('#emails');
            var innerHtml = "";
            $.each(json_source, function (i, value) {
                if (value.IsRead == true) {
                    innerHtml = '<tr><td>' + value.From + '</td><td><a href="Mail.aspx?Type=2&From=' + value.From + '&Subject=' + value.Subject + '">' + value.Subject + '</a></td></tr>';
                } else {
                    innerHtml = '<tr class="isread" ><td>' + value.From + '</td><td><a href="Mail.aspx?Type=2&From=' + value.From + '&Subject=' + value.Subject + '">' + value.Subject + '</a></td></tr>';
                }
                table.append(innerHtml);
            });                        
        },
        error: function (data) {
            var aux = data.d;
            var hello = '';
        }
    });
}

function loadForm() {
    var type = $('#mailType').val();

    if (type == 1) {
        $('#lbl_From').html('To');
    } else {
        $('#lbl_From').html('From');
        $('#ToFrom').prop("readonly", true);
    }

}